import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:ty_smart_watch/ble/ble_util.dart';
import 'package:ty_smart_watch/common/function_id.dart';
import 'package:ty_smart_watch/page/device/device_info_controller.dart';

import '../../common/images_url.dart';

class WatchDetail extends StatelessWidget {
  const WatchDetail({super.key, required this.mac});

  final String mac;

  @override
  Widget build(BuildContext context) {
    DeviceInfoController deviceInfoController = Get.find();
    BleUtil.writeBleData(mac, BleUtil.makeWriteData(functionId: REAL_TIME_DATA));
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Column(
            children: [
              Image.asset(ICON_WATHC_STYLE_1, fit: BoxFit.scaleDown, height: 80),
              Image.asset(ICON_WATCH_SHADOW, width: 80),
            ],
          ),
          const SizedBox(width: 20),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const Text("连接成功"),
              Text(
                mac,
                style: const TextStyle(color: Color.fromARGB(255, 160, 160, 160)),
              ),
              const SizedBox(height: 2),
              Row(children: [
                Obx(
                  () => Text("${deviceInfoController.battery.value}%"),
                ),
                const SizedBox(width: 6),
                Obx(() => Image.asset(
                      getImageUrl(int.parse(deviceInfoController.battery.value)),
                      width: 20,
                      height: 10,
                    )),
              ])
            ],
          ),
        ],
      ),
    );
  }

  String getImageUrl(int battery) {
    if (battery > 85) return BATTERY_1;
    if (battery > 55) return BATTERY_2;
    if (battery > 35) return BATTERY_3;
    return BATTERY_4;
  }
}
